<template>
	<view class="home">
		<!-- 自定义导航 -->
		<navbar></navbar>
		<!-- 选项卡区域 -->
		<tab :list="tabList" @tab="tab" :tabIndex="tabIndex"></tab>
		
		<view class="home-list">
			<list :tab="tabList" :activeIndex="activeIndex" @change="change"></list>
		</view>
		
	</view>
</template>

<script>
	import {mapState} from 'vuex'
	export default {
		data() {
			return {
				title: 'Hello',
				tabList: [],
				tabIndex: 0,
				activeIndex: 0
			}
		},
		computed: {
			...mapState(['userInfo'])
		},
		watch: {
			userInfo(newVal) {
				this.getLabel()
			}
		},
		onLoad() {
			uni.$on('labelChange', res => {
				this.tabList = []
				this.tabIndex = 0
				this.activeIndex = 0
				this.getLabel()
			})
		},
		methods: {
			getLabel() {
				// console.log(this.$api);
				this.$api.get_label().then((res) => {
					const { data } = res
					data.unshift({
						name: '全部'
					})
					this.tabList = data
				})
			},
			tab({data, index}) {
				// console.log(data,index);
				this.activeIndex = index
			},
			change(current) {
				this.tabIndex = current
				this.activeIndex = current
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		display: flex;
		.home {
			display: flex;
			flex-direction: column;
			flex: 1;
			// overflow: hidden;
			.scroll {
				flex: 1;
				overflow: hidden;
				box-sizing: border-box;
				.list-scroll {
					height: 100%;
					display: flex;
					flex-direction: column;
				}
			}
			.home-list {
				flex: 1;
				box-sizing: border-box;
			}
		}
	}
</style>
